import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { Apilogin } from '@/api/server';
import { ElMessage } from "element-plus";
// import { mix } from '../utils/color.ts'
export const useStore = defineStore('counter', () => {
  const token = ref('');
  const img = ref('');
  const user_id = ref('')
  async function apigetlogin(params: any) {
    const { data } = await Apilogin(params)
    console.log(data, '======data');
    token.value = data.data.token;
    img.value = data.data.image;
    user_id.value = data.data.user_id;
    localStorage.setItem('token', token.value)
    localStorage.setItem('img', img.value);
    localStorage.setItem('user_id', user_id.value)
    window.location.href = '/home/index'
    ElMessage({
      message: "登录成功",
      type: "success",
    })
  }

  const themeConfig = {
    primary: '#4060c7',
    tabColor: '#FFFFFF',
    footColor: '#606266',
    backgroundColor: '#FFFFFF',
    textColor: '#00000099',
    istags: true
  }

  function BlackC(primary: any) {
    themeConfig.primary = primary;
  }
  function BlackA(primary: any) {
    themeConfig.tabColor = primary
    if (primary === '#FFFFFF') {
      themeConfig.footColor = "#606266";
    } else {
      themeConfig.footColor = "#ffffff";
    }
  }
  function BlackB(primary: any) {
    if (primary) {
      themeConfig.backgroundColor = "#ffffff";
      themeConfig.textColor = "#00000099";
    } else {
      themeConfig.backgroundColor = '#1d2129';
      themeConfig.textColor = '#bdbdc0';
    }
  }

  function BlackL(primary: any) {
    if (primary) {
      themeConfig.istags = false;
    } else {
      themeConfig.istags = true;
    }
  }
  return { token, themeConfig, img, user_id, apigetlogin, BlackC, BlackA, BlackB, BlackL }
})
// function mix(str: any, mixWhite: string, arg2: number): string | null {
//   throw new Error('Function not implemented.');
// }

